package com.core.family.admin.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Objects;

import org.springframework.stereotype.Service;
import com.core.family.admin.domain.User;
import com.core.family.admin.service.UserService;
import com.core.family.admin.domain.req.UserReq;
import com.core.common.gen.BaseQuery;
import com.core.common.gen.PageQuery;
import com.core.common.annotation.MenuDesc;
import com.core.common.domain.response.R;
import io.swagger.annotations.Api;
import org.springframework.beans.BeanUtils;


/**
 * @author honglei
 * @version 1.0
 * @time: 2024-6-17 15:04:02
 * @Description 服务实现层 系统用户表
 */
@MenuDesc(desc = "系统用户表", code = "ucUser")
@Api(tags = "UserController 系统用户表")
@RestController
@RequestMapping("/api/ucUser/")
public class UserController {

    @Autowired
    UserService service;


    /**
     * 根据id获取详情
     *
     * @param request
     * @param id
     * @return
     */
    @GetMapping(value = "get/{id}")
    public R get(HttpServletRequest request, @PathVariable("id") Long id) {
        return R.ok(service.getById(id));
    }


    /**
     * 分页查询
     *
     * @return
     */
    @RequestMapping(value = "getPage", method = {RequestMethod.GET, RequestMethod.POST})
    public R getPage(@RequestBody UserReq queryReq) {

        return R.ok(service.selectPage(queryReq));
    }

    /**
     * 批量查询
     *
     * @return
     */
    @RequestMapping(value = "getList", method = {RequestMethod.GET, RequestMethod.POST})
    public R getList(@RequestBody UserReq queryReq) {
        return R.ok(service.selectList(queryReq));
    }

    /**
     * 普通更新
     *
     * @param bean
     * @return
     */
    @PostMapping(value = "edit")
    public R edit(@RequestBody User bean) {
        return R.ok(service.updateById(bean));
    }


    /**
     * 新增
     *
     * @param bean
     * @return
     */
    @PostMapping(value = "create")
    public R create(@RequestBody User bean) {
        return R.ok(service.save(bean));
    }

    /**
     * 删除
     *
     * @param request
     * @param id
     * @return
     */
    @PostMapping(value = "del/{id}")
    public R del(HttpServletRequest request, @PathVariable("id") Long id) {
        return R.ok(service.removeById(id));
    }

    /**
     * 批量删除
     *
     * @param request
     * @param ids
     * @return
     */
    @PostMapping(value = "delBatch")
    public R batchDel(HttpServletRequest request, @RequestBody List<String> ids) {
        return R.ok(service.removeByIds(ids));
    }


}
